package avicit.bdp.dms.tdm.rest;

import avicit.bdp.dms.tdm.dto.AppClientDTO;
import avicit.bdp.dms.tdm.service.AppClientService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "资产app应用接口")
@RequestMapping("/api/bdp/dms/asset/appClient")
public class AppClientRest {
    private static final Logger logger = LoggerFactory.getLogger(AppClientRest.class);

    @Autowired
    private AppClientService appClientService;
    @ApiOperation(value = "保存应用")
    @PostMapping("/save")
    public ResponseMsg<AppClientDTO> save(@RequestBody AppClientDTO dto) {
        ResponseMsg<AppClientDTO> responseMsg = new ResponseMsg<>();
        appClientService.save(dto);
        return responseMsg;
    }

    @ApiOperation(value = "分页查询应用")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "关键字", name = "keyWords", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping("/getAppClientPageList")
    public ResponseMsg<QueryRespBean<AppClientDTO>> getAppClientPageList(
            @RequestParam(required = false) String keyWords,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        ResponseMsg<QueryRespBean<AppClientDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<AppClientDTO> queryRespBean = appClientService.getAppClientPageList(keyWords, pageNo, pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @ApiOperation(value = "删除应用")
    @PostMapping("/deleteApp")
    public ResponseMsg<AppClientDTO> deleteApp(@RequestBody AppClientDTO dto) {
        ResponseMsg<AppClientDTO> responseMsg = new ResponseMsg<>();
        appClientService.deleteApp(dto);
        return responseMsg;
    }
    @ApiOperation(value = "查询应用列表")
    @GetMapping("/getAppClientList")
    public ResponseMsg<List<AppClientDTO>> getAppClientList() {
        ResponseMsg<List<AppClientDTO>> responseMsg = new ResponseMsg<>();
        List<AppClientDTO> list = appClientService.getAppClientList();
        responseMsg.setResponseBody(list);
        return responseMsg;
    }
}